package de.haw.main;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import de.haw.algorithm.ExternalMergeSort;
import de.haw.generator.NumberGenerator;
import de.haw.main.test.FolgeTest;

public class Starter {

	static Logger logger = Logger.getLogger(Starter.class);

	private static final int ANZAHL_BAENDER = 8;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		logger.setLevel(Level.ALL);

		File file = NumberGenerator.generateFile();

		Date start = new Date();
		File sortiert = null;
		try {
			sortiert = ExternalMergeSort.sortiere(file, ANZAHL_BAENDER);
		} catch (IOException e) {
			e.printStackTrace();
		}
		Date end = new Date();

		// Statistik ausgeben
		Long duration = Long.valueOf((end.getTime() - start.getTime()));
		Calendar cal = Calendar.getInstance(Locale.GERMANY);
		cal.setTimeInMillis(duration);
		logger.info(String.format("Duration:"));
		logger.info(String.format("\t%d:%d:%d", cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND)));
		logger.info(String.format("\t%s ms", duration.toString()));

		// Testen
		try {
			new FolgeTest(sortiert).test();
		} catch (FileNotFoundException e) {
			logger.error(e);
		} finally {
			System.exit(0);
		}
	}

}
